package kalender.backend;

import javax.persistence.*;


public class DatabaseManager {
	public static void createTable(int num) throws BackendException {
		try {
			EntityManagerFactory factory = Persistence.createEntityManagerFactory("derp");
			EntityManager em = factory.createEntityManager();
			
			em.getTransaction().begin();
			
			em.createNativeQuery("CREATE TABLE test" + num + " (id INT)").executeUpdate();
			
			em.getTransaction().commit();
		} catch (IllegalStateException e) {
            e.printStackTrace();
			throw new BackendException("Databasfel. Var god försök igen.", e);			
		} catch (IllegalArgumentException e) {
            e.printStackTrace();
			throw new BackendException("Databasfel. Var god försök igen.", e);			
		} catch (TransactionRequiredException e) {
            e.printStackTrace();
			throw new BackendException("Databasfel. Var god försök igen.", e);		
		}
	}
}
